import store from 'store/store';
import {whiteRouter} from '../util/config'
import {Message} from 'element-ui';
export function defined(router){
    let flag=true;
    router.beforeEach(async (to,from,next)=>{
        console.log(to);
        if(flag){
            flag=false
            await store.dispatch('autoLogin',to)
        }
        if(JSON.stringify(store.state.user.userInfo)==='{}'){
            const rootName=to.name&&to.name.split('-')[0]
            if(!whiteRouter.includes(rootName)){
                next()
            }else{
                Message.closeAll()
                Message({
                    message:'您还没登录',
                    type:'error'
                })
            }
        }
        next()
    })
    router.beforeResolve((to,from,next)=>{
        next()
    })
    router.afterEach((to,from)=>{
        
    })
}